package com.cumulus.MoveCopy;

import java.util.ArrayList;
import java.util.Collections;

import android.media.AudioManager;
import android.media.SoundPool;
import android.media.SoundPool.OnLoadCompleteListener;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;

/*
 * class MainActivity
 * Start screen, appears from entry into app
 * Navigates to ReplyActivity
 * 
 */

public class MainActivity extends Activity   {

	    
    private static final String TAG = "MainActivityC";
    private int _numPlayers;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        _numPlayers = 2;        
    }
    
    public void onResume() {
    	super.onResume();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    public void onPause() {
    	super.onPause();
    }
    
    
    /*
     * startCreateOwnActivity
     * Read number of players set by user in num_players EditText
     * Create ArrayList of players with designated initial capacity
     * Send extras to new Intent (players ArrayList and index of next player (0))
     * Start next Activity (CreateOwnActivity)
     */
    public void startCreateOwnActivity(View view) {
    	Log.d(TAG, "create own activity called");
    	
    	// _numPlayers used instead of number_players
    	/*String inEditText = ((EditText)(findViewById(R.id.num_players))).getText().toString();
    	
    	int number_players;
    	if (inEditText.length()==0) 
    		number_players = 2;
    	else 
    		number_players = Integer.parseInt(inEditText);
		*/
    	ArrayList<Integer> players = new ArrayList<Integer>(Collections.nCopies(_numPlayers,0));
    	
    	Log.d(TAG, "number of players: "+ _numPlayers);
        Intent intent = new Intent(MainActivity.this, CreateOwnActivity.class);
        intent.putIntegerArrayListExtra("player_arr", players);
        intent.putIntegerArrayListExtra("rounds_played", players);
        intent.putExtra("current_index",0);
        intent.putExtra("recorder_index", -1);
        intent.putExtra("num_rounds", 0);
        startActivity(intent);
    }
    
    public void addPlayerNumber(View view) {
    	Log.d(TAG, "addPlayerNumber called");
    	_numPlayers ++;
		((TextView)(findViewById(R.id.num_players_label))).setText("Number of Players: " + _numPlayers);
    }
    
    public void subtractPlayerNumber(View view) {
    	if(_numPlayers > 2){
    		_numPlayers --;
    		((TextView)(findViewById(R.id.num_players_label))).setText("Number of Players: " + _numPlayers);
    	}
    }
    
    public void onBackPressed() {
    	   Intent intent = new Intent(Intent.ACTION_MAIN);
    	   intent.addCategory(Intent.CATEGORY_HOME);
    	   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    	   startActivity(intent);
    }
    
    public void showSettings(View view) {
        Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
        startActivity(intent);

    }
 }